Skip to content

test(ui): bound the copy wait by a deadline, not an attempt count - #3477

Merged
kwakayama merged 2 commits into
mainfrom
fix/code-block-wait-deadline
Aug 8, 2026
Merged

test(ui): bound the copy wait by a deadline, not an attempt count#3477
kwakayama merged 2 commits into
mainfrom
fix/code-block-wait-deadline

Conversation

@kojiwakayama

@kojiwakayama kojiwakayama commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #3476, which merged before this landed on its branch. The review finding there is currently unaddressed on main, and my reply on that thread claiming it was fixed was premature — this is the change it described.

waitFor stopped after 100 polling iterations. Under load each poll costs more wall-clock, so an attempt count is an arbitrary proxy for how long the test is willing to wait, and it gets shorter in wall-clock terms exactly when the machine is slow — which is when the flake happens. It is now a 2s deadline.

The loop order also changed so the trailing sleep is gone: predicate, then deadline, then sleep. A state landing exactly on the deadline still counts, and a failed final check no longer pays for a tick it will never use.

Still fails loudly rather than waiting a regression out: pointing the predicate at a sentinel that is never true reports Timed out after 2000ms waiting for the copy control to report failure. Verified that explicitly, as with the original.

Summary by CodeRabbit

  • Bug Fixes
    • Improved asynchronous test timing by using a two-second deadline instead of a fixed number of polling attempts.
    • Prevented unnecessary delays when conditions are satisfied.
    • Added clearer timeout errors with the configured duration and condition description.

Under load each poll costs more wall-clock, so a fixed number of attempts is
an arbitrary proxy for how long the test is willing to wait. The deadline is
checked after the predicate, so a state landing exactly on it still counts,
and before the sleep, so a failed final check does not pay for a tick it will
never use.
@kojiwakayama
kojiwakayama requested a review from kwakayama as a code owner August 8, 2026 18:30
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 24633487-2a10-476a-b2b3-1a612af3d912

📥 Commits

Reviewing files that changed from the base of the PR and between a76027d and 362b4a0.

📒 Files selected for processing (1)
  • src/react/components/ui/code-block.test.tsx

📝 Walkthrough

Walkthrough

The test polling helper replaces a fixed attempt limit with a 2-second wall-clock deadline. It evaluates the predicate before timeout checks, avoids an unnecessary final sleep, and reports the configured duration and description on timeout.

Changes

Polling timeout update

Layer / File(s) Summary
Wall-clock polling deadline
src/react/components/ui/code-block.test.tsx
waitFor now uses a 2-second deadline, checks the predicate before timing out, avoids a final sleep, includes timeout details in the error, and has tests for success, timeout, and sleep behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: kwakayama

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: replacing the copy wait attempt limit with a deadline.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/code-block-wait-deadline

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a76027dbd3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/react/components/ui/code-block.test.tsx Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/react/components/ui/code-block.test.tsx`:
- Around line 79-91: Add focused direct tests for the waitFor helper covering a
predicate that succeeds exactly at the deadline, the configured timeout error
including its description, and a final failed check that does not trigger an
additional sleep. Use deterministic clock/sleep control rather than real delays,
and preserve the existing WAIT_FOR_TIMEOUT_MS contract.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bcfd408c-f79f-406a-8d2f-daf778b1f1d1

📥 Commits

Reviewing files that changed from the base of the PR and between 1cdeef4 and a76027d.

📒 Files selected for processing (1)
  • src/react/components/ui/code-block.test.tsx

Comment thread src/react/components/ui/code-block.test.tsx Outdated
A wall clock corrected mid-run by NTP or a VM host can jump backwards, holding
the loop open past its bound, or forwards, timing out a test that was about to
pass. Elapsed time is what this measures, so it now measures it with
`performance.now()`.

`waitFor` also had no tests of its own, which matters more than it looks: it
decides whether the clipboard assertions run against a settled render, so a
version that resolved early or swallowed its timeout would leave those tests
passing without checking anything. Four cases now pin the contract -- returning
on the poll that succeeds, accepting a state that arrives late, throwing an
error naming its timeout, and sleeping between polls but never after the check
that gives up. The timeout is injectable so they run in milliseconds.

I confirmed the trailing-sleep case fails when the loop is reordered to sleep
before its deadline check, rather than trusting it green.
@kwakayama
kwakayama enabled auto-merge August 8, 2026 19:10
@kwakayama
kwakayama added this pull request to the merge queue Aug 8, 2026
Merged via the queue into main with commit ee9df12 Aug 8, 2026
31 checks passed
@kwakayama
kwakayama deleted the fix/code-block-wait-deadline branch August 8, 2026 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants